package com.ruoyi.web.controller.business;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.KnowledgeMap;
import com.ruoyi.business.service.IKnowledgeMapService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 知识地图Controller
 *
 * @author ruoyi
 * @date 2024-11-21
 */
@RestController
@RequestMapping("/business/map")
@Api(tags = "知识地图管理 API") // 添加类级别的 Swagger 注解
public class KnowledgeMapController extends BaseController
{
    @Autowired
    private IKnowledgeMapService knowledgeMapService;

    /**
     * 查询知识地图列表
     */
    @PreAuthorize("@ss.hasPermi('business:map:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询知识地图列表", notes = "根据条件查询知识地图列表")
    public TableDataInfo list(KnowledgeMap knowledgeMap)
    {
        startPage();
        List<KnowledgeMap> list = knowledgeMapService.selectKnowledgeMapList(knowledgeMap);
        return getDataTable(list);
    }

    /**
     * 导出知识地图列表
     */
    @PreAuthorize("@ss.hasPermi('business:map:export')")
    @Log(title = "知识地图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出知识地图列表", notes = "导出符合条件的知识地图列表为Excel文件")
    public void export(HttpServletResponse response, KnowledgeMap knowledgeMap)
    {
        List<KnowledgeMap> list = knowledgeMapService.selectKnowledgeMapList(knowledgeMap);
        ExcelUtil<KnowledgeMap> util = new ExcelUtil<KnowledgeMap>(KnowledgeMap.class);
        util.exportExcel(response, list, "知识地图数据");
    }

    /**
     * 获取知识地图详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:map:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取知识地图详细信息", notes = "根据ID获取知识地图的详细信息")
    public AjaxResult getInfo(@ApiParam(value = "知识地图ID", required = true) @PathVariable("id") Long id)
    {
        return success(knowledgeMapService.selectKnowledgeMapById(id));
    }

    /**
     * 新增知识地图
     */
    @PreAuthorize("@ss.hasPermi('business:map:add')")
    @Log(title = "知识地图", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增知识地图", notes = "新增一条知识地图记录")
    public AjaxResult add(@ApiParam(value = "知识地图对象", required = true) @RequestBody KnowledgeMap knowledgeMap)
    {
        return toAjax(knowledgeMapService.insertKnowledgeMap(knowledgeMap));
    }

    /**
     * 修改知识地图
     */
    @PreAuthorize("@ss.hasPermi('business:map:edit')")
    @Log(title = "知识地图", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改知识地图", notes = "根据ID修改知识地图记录")
    public AjaxResult edit(@ApiParam(value = "知识地图对象", required = true) @RequestBody KnowledgeMap knowledgeMap)
    {
        return toAjax(knowledgeMapService.updateKnowledgeMap(knowledgeMap));
    }

    /**
     * 删除知识地图
     */
    @PreAuthorize("@ss.hasPermi('business:map:remove')")
    @Log(title = "知识地图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除知识地图", notes = "根据ID数组删除知识地图记录")
    public AjaxResult remove(@ApiParam(value = "知识地图ID数组", required = true) @PathVariable Long[] ids)
    {
        return toAjax(knowledgeMapService.deleteKnowledgeMapByIds(ids));
    }
}
